function HelpWidget(Id, properties){
   this.id = Id;
   this.param = new Param();
   $.extend(this.param, properties);
   this.shown = false;
}
extend(HelpWidget,BaseWidget);
//properties = {button: testo | imagewidget, content: testo, attach:string}
//testo vuol dire una stringa oppure un array parsabile col parsestring di saverio


HelpWidget.prototype.getRenderString = function(){
   var cntt = '<div id="'+this.id+'_help_pwin">'+
      this.parseString(this.param.content)+'</div>'; //popup vero e proprio
   var bgr = '<div id="'+this.id+'_help_back"></div>'; //background nero
   return cntt+bgr;
}

//HelpWidget.prototype.parseString = function(asd){
//	return asd;
//}

HelpWidget.prototype.postRender = function(){
   var tasto = $('<span></span>');
   tasto.attr('id', this.id+'_help');
   tasto.addClass('helpbutton');
   if(typeof this.param.button == 'string'){
      tasto.text(this.param.button);
   }
   else if(this.param.button instanceof ImageWidget){
      this.param.button.render(this.id+'_help');
   }
   else
      alert('bottone help sbagliato');

//	$('#'+this.param.attach).css('display', 'inline');
//	tasto.css('float', 'left');
	tasto.css('display', 'inline');
//	$('#'+this.param.attach).css('float', 'left');
   $('#'+this.param.attach).append(tasto);
   var questo = this;
   tasto.click(function(){questo.showPopup()});
	$("#"+this.id+'_help_back').click(function(){questo.hidePopup()});

	var backstyle = {
		'display':'none',
		'position':'fixed',
		'height':'100%',
		'width':'100%',
		'top':'0',
		'left':'0',
		'background':'#000000',
		'border':'1px solid #cecece',
		'z-index':'101'
   };

   var contentstyle = {
		'display':'none',
		'position':'fixed',
		'background':'#FFFFFF',
		'border':'2px solid #cecece',
		'z-index':'102'
   };

	$("#"+this.id+'_help_back').css(backstyle);
	$("#"+this.id+'_help_pwin').css(contentstyle);
}

HelpWidget.prototype.showPopup = function(){
   if(!this.shown){
      $("#"+this.id+'_help_back').css({
      "opacity": "0.7"
      });
      $("#"+this.id+'_help_back').fadeIn("slow");
      $("#"+this.id+'_help_pwin').fadeIn("slow");

		var windowWidth = $(document).width();
		var windowHeight = $(document).height();
		var popupHeight = $("#"+this.id+'_help_pwin').height();

		$("#"+this.id+'_help_pwin').css({
			"position": "absolute",
			"max-width": windowWidth/3,
			"top": windowHeight/2-popupHeight/2
		}).css('left', (windowWidth-$("#"+this.id+'_help_pwin').width())/2);
      this.shown = true;
	}
}

HelpWidget.prototype.hidePopup = function(){
	if(this.shown){
		$("#"+this.id+'_help_back').fadeOut("slow");
		$("#"+this.id+'_help_pwin').fadeOut("slow");
		this.shown = false;
	}
}

HelpWidget.prototype.deleteMe = function() {
    var that = this;
    $('#' + that.id + '_help_back').remove();
    $('#' + that.id + '_help_pwin').remove();
}